OE pi benchmark

integer n = 2400, 
        len = floor(10*n/3) 
sequence a = repeat(2,len) 
integer nines = 0, 
        predigit = 0 
sequence res = "" 
    for j=1 to n do 
        integer q = 0 
        for i=len to 1 by -1 do 
            integer x = 10*a[i]+q*i, 
                    d = 2*i-1 
            a[i] = remainder(x,d) 
            q = floor(x/d) 
        end for 
        a[1] = remainder(q,10) 
        q = floor(q/10) 
        if q=9 then 
            nines = nines+1 
        else 
            integer nine = '9' 
            if q=10 then 
                predigit += 1 
                q = 0 
                nine = '0' 
            end if 
            res &= predigit+'0' 
            for k=1 to nines do 
                res &= nine 
            end for 
            predigit = q 
            nines = 0 
        end if 
    end for 
    res &= predigit+'0' 
    puts(1,res) 

converted from the Phix version

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu